package cn.jingzhuan.element.demo.view.util.audio

import android.app.Activity
import android.app.Application
import android.os.Bundle

/**
 * Created by KNOX.
 */
class LifecycleHandler: Application.ActivityLifecycleCallbacks {

  private var resumed: Int = 0
  private var paused: Int = 0
  private var started: Int = 0
  private var stopped: Int = 0

  override fun onActivityPaused(activity: Activity?) {
    ++paused
  }

  override fun onActivityResumed(activity: Activity?) {
    ++resumed
  }

  override fun onActivityStarted(activity: Activity?) {
    ++started
  }

  override fun onActivityDestroyed(activity: Activity?) {
  }

  override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
  }

  override fun onActivityStopped(activity: Activity?) {
    ++stopped
  }

  override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
  }

  fun isRunningInForeground() = resumed > paused
}